library(tidyverse)
library(modelr)
library(GGally)
library(ggfortify)
library(relaimpo)
library(lm.beta)

MVP 1

# read in dataset
house_data <- read_csv("data/kc_house_data.csv") 
Rows: 21613 Columns: 21
── Column specification ─────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr   (1): id
dbl  (19): price, bedrooms, bathrooms, sqft_living, sqft_lot, floors, waterfront, view, condition, grade, sqft_above, sqf...
dttm  (1): date

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# clean dataset
house_tidy <- house_data %>% 
  dplyr::select(-c(date, id, sqft_living15, sqft_lot15, zipcode)) %>% 
  mutate(yr_renovated = ifelse(yr_renovated == 0, FALSE, TRUE)) %>% 
  mutate(waterfront = ifelse(waterfront == 0, FALSE, TRUE)) %>% 
  rename("renovated" = "yr_renovated") %>% 
  mutate(grade = ifelse(grade <= 3, "poor", ifelse(grade <= 7, "average", "good")))
  

MVP 2

# use alias() to check for any variables that lead to an alias
alias(lm(price ~ ., data = house_tidy))
Model :
price ~ bedrooms + bathrooms + sqft_living + sqft_lot + floors + 
    waterfront + view + condition + grade + sqft_above + sqft_basement + 
    yr_built + renovated + lat + long

Complete :
              (Intercept) bedrooms bathrooms sqft_living sqft_lot floors waterfrontTRUE view condition gradegood gradepoor
sqft_basement  0           0        0         1           0        0      0              0    0         0         0       
              sqft_above yr_built renovatedTRUE lat long
sqft_basement -1          0        0             0   0  
# remove sqft_basement
house_tidy <- house_tidy %>% 
  dplyr::select(-sqft_basement)

# rerun alias to check that there are now no aliases
alias(lm(price ~ ., data = house_tidy))
Model :
price ~ bedrooms + bathrooms + sqft_living + sqft_lot + floors + 
    waterfront + view + condition + grade + sqft_above + yr_built + 
    renovated + lat + long

MVP 3

ggpairs(house_tidy_numeric)

 plot: [1,1] [>----------------------------------------------------------------------------------------------]  1% est: 0s 
 plot: [1,2] [>----------------------------------------------------------------------------------------------]  1% est: 2s 
 plot: [1,3] [=>---------------------------------------------------------------------------------------------]  2% est: 2s 
 plot: [1,4] [==>--------------------------------------------------------------------------------------------]  3% est: 3s 
 plot: [1,5] [==>--------------------------------------------------------------------------------------------]  3% est: 3s 
 plot: [1,6] [===>-------------------------------------------------------------------------------------------]  4% est: 3s 
 plot: [1,7] [====>------------------------------------------------------------------------------------------]  5% est: 3s 
 plot: [1,8] [====>------------------------------------------------------------------------------------------]  6% est: 3s 
 plot: [1,9] [=====>-----------------------------------------------------------------------------------------]  6% est: 3s 
 plot: [1,10] [======>---------------------------------------------------------------------------------------]  7% est: 3s 
 plot: [1,11] [======>---------------------------------------------------------------------------------------]  8% est: 3s 
 plot: [1,12] [=======>--------------------------------------------------------------------------------------]  8% est: 3s 
 plot: [2,1] [========>--------------------------------------------------------------------------------------]  9% est: 3s 
 plot: [2,2] [========>--------------------------------------------------------------------------------------] 10% est: 3s 
 plot: [2,3] [=========>-------------------------------------------------------------------------------------] 10% est: 3s 
 plot: [2,4] [==========>------------------------------------------------------------------------------------] 11% est: 3s 
 plot: [2,5] [==========>------------------------------------------------------------------------------------] 12% est: 3s 
 plot: [2,6] [===========>-----------------------------------------------------------------------------------] 12% est: 3s 
 plot: [2,7] [============>----------------------------------------------------------------------------------] 13% est: 3s 
 plot: [2,8] [============>----------------------------------------------------------------------------------] 14% est: 3s 
 plot: [2,9] [=============>---------------------------------------------------------------------------------] 15% est: 3s 
 plot: [2,10] [=============>--------------------------------------------------------------------------------] 15% est: 3s 
 plot: [2,11] [==============>-------------------------------------------------------------------------------] 16% est: 3s 
 plot: [2,12] [===============>------------------------------------------------------------------------------] 17% est: 2s 
 plot: [3,1] [===============>-------------------------------------------------------------------------------] 17% est: 2s 
 plot: [3,2] [================>------------------------------------------------------------------------------] 18% est: 2s 
 plot: [3,3] [=================>-----------------------------------------------------------------------------] 19% est: 2s 
 plot: [3,4] [=================>-----------------------------------------------------------------------------] 19% est: 2s 
 plot: [3,5] [==================>----------------------------------------------------------------------------] 20% est: 2s 
 plot: [3,6] [===================>---------------------------------------------------------------------------] 21% est: 2s 
 plot: [3,7] [===================>---------------------------------------------------------------------------] 22% est: 2s 
 plot: [3,8] [====================>--------------------------------------------------------------------------] 22% est: 2s 
 plot: [3,9] [=====================>-------------------------------------------------------------------------] 23% est: 2s 
 plot: [3,10] [=====================>------------------------------------------------------------------------] 24% est: 2s 
 plot: [3,11] [======================>-----------------------------------------------------------------------] 24% est: 2s 
 plot: [3,12] [=======================>----------------------------------------------------------------------] 25% est: 2s 
 plot: [4,1] [=======================>-----------------------------------------------------------------------] 26% est: 2s 
 plot: [4,2] [========================>----------------------------------------------------------------------] 26% est: 2s 
 plot: [4,3] [=========================>---------------------------------------------------------------------] 27% est: 2s 
 plot: [4,4] [=========================>---------------------------------------------------------------------] 28% est: 2s 
 plot: [4,5] [==========================>--------------------------------------------------------------------] 28% est: 2s 
 plot: [4,6] [===========================>-------------------------------------------------------------------] 29% est: 2s 
 plot: [4,7] [===========================>-------------------------------------------------------------------] 30% est: 2s 
 plot: [4,8] [============================>------------------------------------------------------------------] 31% est: 2s 
 plot: [4,9] [=============================>-----------------------------------------------------------------] 31% est: 2s 
 plot: [4,10] [=============================>----------------------------------------------------------------] 32% est: 2s 
 plot: [4,11] [==============================>---------------------------------------------------------------] 33% est: 2s 
 plot: [4,12] [==============================>---------------------------------------------------------------] 33% est: 2s 
 plot: [5,1] [===============================>---------------------------------------------------------------] 34% est: 2s 
 plot: [5,2] [================================>--------------------------------------------------------------] 35% est: 2s 
 plot: [5,3] [=================================>-------------------------------------------------------------] 35% est: 2s 
 plot: [5,4] [=================================>-------------------------------------------------------------] 36% est: 2s 
 plot: [5,5] [==================================>------------------------------------------------------------] 37% est: 2s 
 plot: [5,6] [===================================>-----------------------------------------------------------] 38% est: 2s 
 plot: [5,7] [===================================>-----------------------------------------------------------] 38% est: 2s 
 plot: [5,8] [====================================>----------------------------------------------------------] 39% est: 2s 
 plot: [5,9] [=====================================>---------------------------------------------------------] 40% est: 2s 
 plot: [5,10] [=====================================>--------------------------------------------------------] 40% est: 2s 
 plot: [5,11] [======================================>-------------------------------------------------------] 41% est: 2s 
 plot: [5,12] [======================================>-------------------------------------------------------] 42% est: 2s 
 plot: [6,1] [=======================================>-------------------------------------------------------] 42% est: 2s 
 plot: [6,2] [========================================>------------------------------------------------------] 43% est: 2s 
 plot: [6,3] [=========================================>-----------------------------------------------------] 44% est: 2s 
 plot: [6,4] [=========================================>-----------------------------------------------------] 44% est: 2s 
 plot: [6,5] [==========================================>----------------------------------------------------] 45% est: 2s 
 plot: [6,6] [===========================================>---------------------------------------------------] 46% est: 2s 
 plot: [6,7] [===========================================>---------------------------------------------------] 47% est: 2s 
 plot: [6,8] [============================================>--------------------------------------------------] 47% est: 2s 
 plot: [6,9] [=============================================>-------------------------------------------------] 48% est: 2s 
 plot: [6,10] [=============================================>------------------------------------------------] 49% est: 2s 
 plot: [6,11] [=============================================>------------------------------------------------] 49% est: 2s 
 plot: [6,12] [==============================================>-----------------------------------------------] 50% est: 2s 
 plot: [7,1] [===============================================>-----------------------------------------------] 51% est: 2s 
 plot: [7,2] [================================================>----------------------------------------------] 51% est: 2s 
 plot: [7,3] [================================================>----------------------------------------------] 52% est: 2s 
 plot: [7,4] [=================================================>---------------------------------------------] 53% est: 2s 
 plot: [7,5] [==================================================>--------------------------------------------] 53% est: 2s 
 plot: [7,6] [==================================================>--------------------------------------------] 54% est: 1s 
 plot: [7,7] [===================================================>-------------------------------------------] 55% est: 1s 
 plot: [7,8] [====================================================>------------------------------------------] 56% est: 1s 
 plot: [7,9] [====================================================>------------------------------------------] 56% est: 1s 
 plot: [7,10] [=====================================================>----------------------------------------] 57% est: 1s 
 plot: [7,11] [=====================================================>----------------------------------------] 58% est: 1s 
 plot: [7,12] [======================================================>---------------------------------------] 58% est: 1s 
 plot: [8,1] [=======================================================>---------------------------------------] 59% est: 1s 
 plot: [8,2] [========================================================>--------------------------------------] 60% est: 1s 
 plot: [8,3] [========================================================>--------------------------------------] 60% est: 1s 
 plot: [8,4] [=========================================================>-------------------------------------] 61% est: 1s 
 plot: [8,5] [==========================================================>------------------------------------] 62% est: 1s 
 plot: [8,6] [==========================================================>------------------------------------] 62% est: 1s 
 plot: [8,7] [===========================================================>-----------------------------------] 63% est: 1s 
 plot: [8,8] [============================================================>----------------------------------] 64% est: 1s 
 plot: [8,9] [============================================================>----------------------------------] 65% est: 1s 
 plot: [8,10] [============================================================>---------------------------------] 65% est: 1s 
 plot: [8,11] [=============================================================>--------------------------------] 66% est: 1s 
 plot: [8,12] [==============================================================>-------------------------------] 67% est: 1s 
 plot: [9,1] [===============================================================>-------------------------------] 67% est: 1s 
 plot: [9,2] [================================================================>------------------------------] 68% est: 1s 
 plot: [9,3] [================================================================>------------------------------] 69% est: 1s 
 plot: [9,4] [=================================================================>-----------------------------] 69% est: 1s 
 plot: [9,5] [==================================================================>----------------------------] 70% est: 1s 
 plot: [9,6] [==================================================================>----------------------------] 71% est: 1s 
 plot: [9,7] [===================================================================>---------------------------] 72% est: 1s 
 plot: [9,8] [====================================================================>--------------------------] 72% est: 1s 
 plot: [9,9] [====================================================================>--------------------------] 73% est: 1s 
 plot: [9,10] [====================================================================>-------------------------] 74% est: 1s 
 plot: [9,11] [=====================================================================>------------------------] 74% est: 1s 
 plot: [9,12] [=====================================================================>------------------------] 75% est: 1s 
 plot: [10,1] [======================================================================>-----------------------] 76% est: 1s 
 plot: [10,2] [=======================================================================>----------------------] 76% est: 1s 
 plot: [10,3] [=======================================================================>----------------------] 77% est: 1s 
 plot: [10,4] [========================================================================>---------------------] 78% est: 1s 
 plot: [10,5] [=========================================================================>--------------------] 78% est: 1s 
 plot: [10,6] [=========================================================================>--------------------] 79% est: 1s 
 plot: [10,7] [==========================================================================>-------------------] 80% est: 1s 
 plot: [10,8] [===========================================================================>------------------] 81% est: 1s 
 plot: [10,9] [===========================================================================>------------------] 81% est: 1s 
 plot: [10,10] [===========================================================================>-----------------] 82% est: 1s 
 plot: [10,11] [============================================================================>----------------] 83% est: 1s 
 plot: [10,12] [=============================================================================>---------------] 83% est: 1s 
 plot: [11,1] [==============================================================================>---------------] 84% est: 1s 
 plot: [11,2] [===============================================================================>--------------] 85% est: 1s 
 plot: [11,3] [===============================================================================>--------------] 85% est: 0s 
 plot: [11,4] [================================================================================>-------------] 86% est: 0s 
 plot: [11,5] [=================================================================================>------------] 87% est: 0s 
 plot: [11,6] [=================================================================================>------------] 88% est: 0s 
 plot: [11,7] [==================================================================================>-----------] 88% est: 0s 
 plot: [11,8] [===================================================================================>----------] 89% est: 0s 
 plot: [11,9] [===================================================================================>----------] 90% est: 0s 
 plot: [11,10] [===================================================================================>---------] 90% est: 0s 
 plot: [11,11] [====================================================================================>--------] 91% est: 0s 
 plot: [11,12] [====================================================================================>--------] 92% est: 0s 
 plot: [12,1] [======================================================================================>-------] 92% est: 0s 
 plot: [12,2] [======================================================================================>-------] 93% est: 0s 
 plot: [12,3] [=======================================================================================>------] 94% est: 0s 
 plot: [12,4] [========================================================================================>-----] 94% est: 0s 
 plot: [12,5] [========================================================================================>-----] 95% est: 0s 
 plot: [12,6] [=========================================================================================>----] 96% est: 0s 
 plot: [12,7] [==========================================================================================>---] 97% est: 0s 
 plot: [12,8] [==========================================================================================>---] 97% est: 0s 
 plot: [12,9] [===========================================================================================>--] 98% est: 0s 
 plot: [12,10] [===========================================================================================>-] 99% est: 0s 
 plot: [12,11] [===========================================================================================>-] 99% est: 0s 
 plot: [12,12] [=============================================================================================]100% est: 0s 
                                                                                                                           

ggpairs(house_tidy_nonnumeric)

 plot: [1,1] [=====>-----------------------------------------------------------------------------------------]  6% est: 0s 
 plot: [1,2] [===========>-----------------------------------------------------------------------------------] 12% est: 0s 
 plot: [1,3] [=================>-----------------------------------------------------------------------------] 19% est: 0s 
 plot: [1,4] [=======================>-----------------------------------------------------------------------] 25% est: 0s 
 plot: [2,1] [=============================>-----------------------------------------------------------------] 31% est: 0s 
 plot: [2,2] [===================================>-----------------------------------------------------------] 38% est: 0s 
 plot: [2,3] [=========================================>-----------------------------------------------------] 44% est: 1s 
 plot: [2,4] [===============================================>-----------------------------------------------] 50% est: 0s 
 plot: [3,1] [====================================================>------------------------------------------] 56% est: 0s 
 plot: [3,2] [==========================================================>------------------------------------] 62% est: 0s 
 plot: [3,3] [================================================================>------------------------------] 69% est: 0s 
 plot: [3,4] [======================================================================>------------------------] 75% est: 0s 
 plot: [4,1] [============================================================================>------------------] 81% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [4,2] [==================================================================================>------------] 88% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [4,3] [========================================================================================>------] 94% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [4,4] [===============================================================================================]100% est: 0s 
                                                                                                                           

1st Predictor

# first model price ~ sqft_living
mod_1 <- lm(price ~ sqft_living, data = house_tidy)

summary(mod_1)

Call:
lm(formula = price ~ sqft_living, data = house_tidy)

Residuals:
     Min       1Q   Median       3Q      Max 
-1476062  -147486   -24043   106182  4362067 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -43580.743   4402.690  -9.899   <2e-16 ***
sqft_living    280.624      1.936 144.920   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 261500 on 21611 degrees of freedom
Multiple R-squared:  0.4929,    Adjusted R-squared:  0.4928 
F-statistic: 2.1e+04 on 1 and 21611 DF,  p-value: < 2.2e-16
par(mfrow = c(2, 2))
plot(mod_1)

# second model price ~ sqft_above
mod_2 <- lm(price ~ sqft_above, data = house_tidy)

summary(mod_2)

Call:
lm(formula = price ~ sqft_above, data = house_tidy)

Residuals:
    Min      1Q  Median      3Q     Max 
-913132 -165624  -41468  109327 5339232 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  59953.2     4729.8   12.68   <2e-16 ***
sqft_above     268.5        2.4  111.87   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 292200 on 21611 degrees of freedom
Multiple R-squared:  0.3667,    Adjusted R-squared:  0.3667 
F-statistic: 1.251e+04 on 1 and 21611 DF,  p-value: < 2.2e-16
par(mfrow = c(2, 2))
plot(mod_2)

sqft_living will be used as the first predictor since the r2 value is higher, 50% vs 36%, diagnostics for both models look ok-ish but not great!

Second predictor

prestige_remaining_resid %>%
  ggpairs(aes(colour = waterfront, alpha = 0.5))

 plot: [1,1] [-----------------------------------------------------------------------------------------------]  1% est: 0s 
 plot: [1,2] [>----------------------------------------------------------------------------------------------]  1% est: 6s 
 plot: [1,3] [>----------------------------------------------------------------------------------------------]  2% est: 6s 
 plot: [1,4] [=>---------------------------------------------------------------------------------------------]  2% est: 6s 
 plot: [1,5] [=>---------------------------------------------------------------------------------------------]  3% est: 6s 
 plot: [1,6] [==>--------------------------------------------------------------------------------------------]  3% est: 7s 
 plot: [1,7] [==>--------------------------------------------------------------------------------------------]  4% est: 7s 
 plot: [1,8] [===>-------------------------------------------------------------------------------------------]  4% est: 7s 
 plot: [1,9] [===>-------------------------------------------------------------------------------------------]  5% est: 7s 
 plot: [1,10] [====>-----------------------------------------------------------------------------------------]  5% est: 7s 
 plot: [1,11] [====>-----------------------------------------------------------------------------------------]  6% est: 7s 
 plot: [1,12] [=====>----------------------------------------------------------------------------------------]  6% est: 7s 
 plot: [1,13] [=====>----------------------------------------------------------------------------------------]  7% est: 7s 
 plot: [1,14] [======>---------------------------------------------------------------------------------------]  7% est: 7s 
 plot: [2,1] [======>----------------------------------------------------------------------------------------]  8% est: 7s 
 plot: [2,2] [=======>---------------------------------------------------------------------------------------]  8% est: 7s 
 plot: [2,3] [=======>---------------------------------------------------------------------------------------]  9% est: 7s 
 plot: [2,4] [========>--------------------------------------------------------------------------------------]  9% est: 7s 
 plot: [2,5] [========>--------------------------------------------------------------------------------------] 10% est: 7s 
 plot: [2,6] [=========>-------------------------------------------------------------------------------------] 10% est: 7s 
 plot: [2,7] [=========>-------------------------------------------------------------------------------------] 11% est: 7s 
 plot: [2,8] [==========>------------------------------------------------------------------------------------] 11% est: 7s 
 plot: [2,9] [==========>------------------------------------------------------------------------------------] 12% est: 7s 
 plot: [2,10] [===========>----------------------------------------------------------------------------------] 12% est: 7s 
 plot: [2,11] [===========>----------------------------------------------------------------------------------] 13% est: 7s 
 plot: [2,12] [===========>----------------------------------------------------------------------------------] 13% est: 7s 
 plot: [2,13] [============>---------------------------------------------------------------------------------] 14% est: 7s 
 plot: [2,14] [============>---------------------------------------------------------------------------------] 14% est: 7s 
 plot: [3,1] [=============>---------------------------------------------------------------------------------] 15% est: 7s 
 plot: [3,2] [==============>--------------------------------------------------------------------------------] 15% est: 7s 
 plot: [3,3] [==============>--------------------------------------------------------------------------------] 16% est: 7s 
 plot: [3,4] [===============>-------------------------------------------------------------------------------] 16% est: 7s 
 plot: [3,5] [===============>-------------------------------------------------------------------------------] 17% est: 7s 
 plot: [3,6] [===============>-------------------------------------------------------------------------------] 17% est: 7s 
 plot: [3,7] [================>------------------------------------------------------------------------------] 18% est: 7s 
 plot: [3,8] [================>------------------------------------------------------------------------------] 18% est: 7s 
 plot: [3,9] [=================>-----------------------------------------------------------------------------] 19% est: 7s 
 plot: [3,10] [=================>----------------------------------------------------------------------------] 19% est: 7s 
 plot: [3,11] [==================>---------------------------------------------------------------------------] 20% est: 7s 
 plot: [3,12] [==================>---------------------------------------------------------------------------] 20% est: 7s 
 plot: [3,13] [===================>--------------------------------------------------------------------------] 21% est: 6s 
 plot: [3,14] [===================>--------------------------------------------------------------------------] 21% est: 6s 
 plot: [4,1] [====================>--------------------------------------------------------------------------] 22% est: 6s 
 plot: [4,2] [====================>--------------------------------------------------------------------------] 22% est: 6s 
 plot: [4,3] [=====================>-------------------------------------------------------------------------] 23% est: 6s 
 plot: [4,4] [=====================>-------------------------------------------------------------------------] 23% est: 6s 
 plot: [4,5] [======================>------------------------------------------------------------------------] 24% est: 6s 
 plot: [4,6] [======================>------------------------------------------------------------------------] 24% est: 6s 
 plot: [4,7] [=======================>-----------------------------------------------------------------------] 25% est: 6s 
 plot: [4,8] [=======================>-----------------------------------------------------------------------] 26% est: 6s 
 plot: [4,9] [========================>----------------------------------------------------------------------] 26% est: 6s 
 plot: [4,10] [========================>---------------------------------------------------------------------] 27% est: 6s 
 plot: [4,11] [========================>---------------------------------------------------------------------] 27% est: 6s 
 plot: [4,12] [=========================>--------------------------------------------------------------------] 28% est: 6s 
 plot: [4,13] [=========================>--------------------------------------------------------------------] 28% est: 6s 
 plot: [4,14] [==========================>-------------------------------------------------------------------] 29% est: 6s 
 plot: [5,1] [===========================>-------------------------------------------------------------------] 29% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,2] [===========================>-------------------------------------------------------------------] 30% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,3] [============================>------------------------------------------------------------------] 30% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,4] [============================>------------------------------------------------------------------] 31% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,5] [=============================>-----------------------------------------------------------------] 31% est: 6s 
 plot: [5,6] [=============================>-----------------------------------------------------------------] 32% est: 6s 
 plot: [5,7] [==============================>----------------------------------------------------------------] 32% est: 6s 
 plot: [5,8] [==============================>----------------------------------------------------------------] 33% est: 6s 
 plot: [5,9] [===============================>---------------------------------------------------------------] 33% est: 6s 
 plot: [5,10] [===============================>--------------------------------------------------------------] 34% est: 6s 
 plot: [5,11] [===============================>--------------------------------------------------------------] 34% est: 6s 
 plot: [5,12] [================================>-------------------------------------------------------------] 35% est: 6s 
 plot: [5,13] [================================>-------------------------------------------------------------] 35% est: 6s 
 plot: [5,14] [=================================>------------------------------------------------------------] 36% est: 6s 
 plot: [6,1] [=================================>-------------------------------------------------------------] 36% est: 6s 
 plot: [6,2] [==================================>------------------------------------------------------------] 37% est: 6s 
 plot: [6,3] [==================================>------------------------------------------------------------] 37% est: 6s 
 plot: [6,4] [===================================>-----------------------------------------------------------] 38% est: 6s 
 plot: [6,5] [===================================>-----------------------------------------------------------] 38% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [====================================>----------------------------------------------------------] 39% est: 6s 
 plot: [6,7] [====================================>----------------------------------------------------------] 39% est: 6s 
 plot: [6,8] [=====================================>---------------------------------------------------------] 40% est: 6s 
 plot: [6,9] [=====================================>---------------------------------------------------------] 40% est: 6s 
 plot: [6,10] [=====================================>--------------------------------------------------------] 41% est: 6s 
 plot: [6,11] [======================================>-------------------------------------------------------] 41% est: 6s 
 plot: [6,12] [======================================>-------------------------------------------------------] 42% est: 6s 
 plot: [6,13] [=======================================>------------------------------------------------------] 42% est: 6s 
 plot: [6,14] [=======================================>------------------------------------------------------] 43% est: 6s 
 plot: [7,1] [========================================>------------------------------------------------------] 43% est: 6s 
 plot: [7,2] [=========================================>-----------------------------------------------------] 44% est: 6s 
 plot: [7,3] [=========================================>-----------------------------------------------------] 44% est: 6s 
 plot: [7,4] [==========================================>----------------------------------------------------] 45% est: 6s 
 plot: [7,5] [==========================================>----------------------------------------------------] 45% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,6] [===========================================>---------------------------------------------------] 46% est: 6s 
 plot: [7,7] [===========================================>---------------------------------------------------] 46% est: 5s 
 plot: [7,8] [============================================>--------------------------------------------------] 47% est: 5s 
 plot: [7,9] [============================================>--------------------------------------------------] 47% est: 5s 
 plot: [7,10] [============================================>-------------------------------------------------] 48% est: 5s 
 plot: [7,11] [=============================================>------------------------------------------------] 48% est: 5s 
 plot: [7,12] [=============================================>------------------------------------------------] 49% est: 5s 
 plot: [7,13] [==============================================>-----------------------------------------------] 49% est: 5s 
 plot: [7,14] [==============================================>-----------------------------------------------] 50% est: 5s 
 plot: [8,1] [===============================================>-----------------------------------------------] 51% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,2] [===============================================>-----------------------------------------------] 51% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,3] [================================================>----------------------------------------------] 52% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,4] [================================================>----------------------------------------------] 52% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,5] [=================================================>---------------------------------------------] 53% est: 5s 
 plot: [8,6] [=================================================>---------------------------------------------] 53% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,7] [==================================================>--------------------------------------------] 54% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,8] [==================================================>--------------------------------------------] 54% est: 5s 
 plot: [8,9] [===================================================>-------------------------------------------] 55% est: 5s 
 plot: [8,10] [===================================================>------------------------------------------] 55% est: 5s 
 plot: [8,11] [===================================================>------------------------------------------] 56% est: 5s 
 plot: [8,12] [====================================================>-----------------------------------------] 56% est: 5s 
 plot: [8,13] [====================================================>-----------------------------------------] 57% est: 5s 
 plot: [8,14] [=====================================================>----------------------------------------] 57% est: 5s 
 plot: [9,1] [======================================================>----------------------------------------] 58% est: 5s 
 plot: [9,2] [======================================================>----------------------------------------] 58% est: 5s 
 plot: [9,3] [=======================================================>---------------------------------------] 59% est: 5s 
 plot: [9,4] [=======================================================>---------------------------------------] 59% est: 5s 
 plot: [9,5] [========================================================>--------------------------------------] 60% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,6] [========================================================>--------------------------------------] 60% est: 4s 
 plot: [9,7] [=========================================================>-------------------------------------] 61% est: 4s 
 plot: [9,8] [=========================================================>-------------------------------------] 61% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,9] [==========================================================>------------------------------------] 62% est: 4s 
 plot: [9,10] [==========================================================>-----------------------------------] 62% est: 4s 
 plot: [9,11] [==========================================================>-----------------------------------] 63% est: 4s 
 plot: [9,12] [==========================================================>-----------------------------------] 63% est: 4s 
 plot: [9,13] [===========================================================>----------------------------------] 64% est: 4s 
 plot: [9,14] [===========================================================>----------------------------------] 64% est: 4s 
 plot: [10,1] [============================================================>---------------------------------] 65% est: 4s 
 plot: [10,2] [============================================================>---------------------------------] 65% est: 4s 
 plot: [10,3] [=============================================================>--------------------------------] 66% est: 4s 
 plot: [10,4] [=============================================================>--------------------------------] 66% est: 4s 
 plot: [10,5] [==============================================================>-------------------------------] 67% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,6] [==============================================================>-------------------------------] 67% est: 4s 
 plot: [10,7] [===============================================================>------------------------------] 68% est: 4s 
 plot: [10,8] [===============================================================>------------------------------] 68% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,9] [================================================================>-----------------------------] 69% est: 4s 
 plot: [10,10] [================================================================>----------------------------] 69% est: 3s 
 plot: [10,11] [================================================================>----------------------------] 70% est: 3s 
 plot: [10,12] [================================================================>----------------------------] 70% est: 3s 
 plot: [10,13] [=================================================================>---------------------------] 71% est: 3s 
 plot: [10,14] [=================================================================>---------------------------] 71% est: 3s 
 plot: [11,1] [===================================================================>--------------------------] 72% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,2] [===================================================================>--------------------------] 72% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,3] [====================================================================>-------------------------] 73% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,4] [====================================================================>-------------------------] 73% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,5] [=====================================================================>------------------------] 74% est: 3s 
 plot: [11,6] [=====================================================================>------------------------] 74% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,7] [=====================================================================>------------------------] 75% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,8] [======================================================================>-----------------------] 76% est: 3s 
 plot: [11,9] [======================================================================>-----------------------] 76% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,10] [======================================================================>----------------------] 77% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,11] [=======================================================================>---------------------] 77% est: 3s 
 plot: [11,12] [=======================================================================>---------------------] 78% est: 3s 
 plot: [11,13] [========================================================================>--------------------] 78% est: 3s 
 plot: [11,14] [========================================================================>--------------------] 79% est: 3s 
 plot: [12,1] [=========================================================================>--------------------] 79% est: 2s 
 plot: [12,2] [==========================================================================>-------------------] 80% est: 2s 
 plot: [12,3] [==========================================================================>-------------------] 80% est: 2s 
 plot: [12,4] [===========================================================================>------------------] 81% est: 2s 
 plot: [12,5] [===========================================================================>------------------] 81% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,6] [============================================================================>-----------------] 82% est: 2s 
 plot: [12,7] [============================================================================>-----------------] 82% est: 2s 
 plot: [12,8] [=============================================================================>----------------] 83% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,9] [=============================================================================>----------------] 83% est: 2s 
 plot: [12,10] [=============================================================================>---------------] 84% est: 2s 
 plot: [12,11] [=============================================================================>---------------] 84% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,12] [==============================================================================>--------------] 85% est: 2s 
 plot: [12,13] [==============================================================================>--------------] 85% est: 2s 
 plot: [12,14] [===============================================================================>-------------] 86% est: 2s 
 plot: [13,1] [================================================================================>-------------] 86% est: 2s 
 plot: [13,2] [=================================================================================>------------] 87% est: 2s 
 plot: [13,3] [=================================================================================>------------] 87% est: 2s 
 plot: [13,4] [=================================================================================>------------] 88% est: 2s 
 plot: [13,5] [==================================================================================>-----------] 88% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,6] [==================================================================================>-----------] 89% est: 1s 
 plot: [13,7] [===================================================================================>----------] 89% est: 1s 
 plot: [13,8] [===================================================================================>----------] 90% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,9] [====================================================================================>---------] 90% est: 1s 
 plot: [13,10] [===================================================================================>---------] 91% est: 1s 
 plot: [13,11] [====================================================================================>--------] 91% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,12] [====================================================================================>--------] 92% est: 1s 
 plot: [13,13] [=====================================================================================>-------] 92% est: 1s 
 plot: [13,14] [=====================================================================================>-------] 93% est: 1s 
 plot: [14,1] [=======================================================================================>------] 93% est: 1s 
 plot: [14,2] [=======================================================================================>------] 94% est: 1s 
 plot: [14,3] [========================================================================================>-----] 94% est: 1s 
 plot: [14,4] [========================================================================================>-----] 95% est: 1s 
 plot: [14,5] [=========================================================================================>----] 95% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,6] [=========================================================================================>----] 96% est: 1s 
 plot: [14,7] [==========================================================================================>---] 96% est: 0s 
 plot: [14,8] [==========================================================================================>---] 97% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,9] [===========================================================================================>--] 97% est: 0s 
 plot: [14,10] [==========================================================================================>--] 98% est: 0s 
 plot: [14,11] [===========================================================================================>-] 98% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,12] [===========================================================================================>-] 99% est: 0s 
 plot: [14,13] [============================================================================================>] 99% est: 0s 
 plot: [14,14] [=============================================================================================]100% est: 0s 
                                                                                                                           

mod_3 <- lm(price ~ sqft_living + yr_built, data = house_tidy)

summary(mod_3)

Call:
lm(formula = price ~ sqft_living + yr_built, data = house_tidy)

Residuals:
     Min       1Q   Median       3Q      Max 
-1684544  -137797   -20753   105703  4036827 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  4.546e+06  1.206e+05   37.69   <2e-16 ***
sqft_living  3.046e+02  1.977e+00  154.03   <2e-16 ***
yr_built    -2.354e+03  6.183e+01  -38.07   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 253100 on 21610 degrees of freedom
Multiple R-squared:  0.5247,    Adjusted R-squared:  0.5247 
F-statistic: 1.193e+04 on 2 and 21610 DF,  p-value: < 2.2e-16
par(mfrow = c(2, 2))
plot(mod_3)

mod_4 <- lm(price ~ sqft_living + lat, data = house_tidy)

summary(mod_4)

Call:
lm(formula = price ~ sqft_living + lat, data = house_tidy)

Residuals:
     Min       1Q   Median       3Q      Max 
-1487994  -125643   -20309    84613  4368717 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -3.416e+07  5.653e+05  -60.44   <2e-16 ***
sqft_living  2.749e+02  1.794e+00  153.27   <2e-16 ***
lat          7.177e+05  1.189e+04   60.36   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 241900 on 21610 degrees of freedom
Multiple R-squared:  0.566, Adjusted R-squared:  0.566 
F-statistic: 1.409e+04 on 2 and 21610 DF,  p-value: < 2.2e-16
par(mfrow = c(2, 2))
plot(mod_4)

Second predictor will be lat as it gives a slight higher r2 value, 56% vs 52% for yr_built. The diagnostics are almost identical.

Third predictor

prestige_remaining_resid <- house_tidy %>%
  add_residuals(mod_4) %>%
  dplyr::select(-c("price", "sqft_living", "lat"))

prestige_remaining_resid %>%
  ggpairs(aes(colour = waterfront, alpha = 0.5))

 plot: [1,1] [>----------------------------------------------------------------------------------------------]  1% est: 0s 
 plot: [1,2] [>----------------------------------------------------------------------------------------------]  1% est: 6s 
 plot: [1,3] [=>---------------------------------------------------------------------------------------------]  2% est: 6s 
 plot: [1,4] [=>---------------------------------------------------------------------------------------------]  2% est: 5s 
 plot: [1,5] [==>--------------------------------------------------------------------------------------------]  3% est: 5s 
 plot: [1,6] [==>--------------------------------------------------------------------------------------------]  4% est: 6s 
 plot: [1,7] [===>-------------------------------------------------------------------------------------------]  4% est: 6s 
 plot: [1,8] [===>-------------------------------------------------------------------------------------------]  5% est: 6s 
 plot: [1,9] [====>------------------------------------------------------------------------------------------]  5% est: 6s 
 plot: [1,10] [=====>----------------------------------------------------------------------------------------]  6% est: 6s 
 plot: [1,11] [=====>----------------------------------------------------------------------------------------]  7% est: 6s 
 plot: [1,12] [======>---------------------------------------------------------------------------------------]  7% est: 6s 
 plot: [1,13] [======>---------------------------------------------------------------------------------------]  8% est: 6s 
 plot: [2,1] [=======>---------------------------------------------------------------------------------------]  8% est: 6s 
 plot: [2,2] [=======>---------------------------------------------------------------------------------------]  9% est: 6s 
 plot: [2,3] [========>--------------------------------------------------------------------------------------]  9% est: 6s 
 plot: [2,4] [=========>-------------------------------------------------------------------------------------] 10% est: 6s 
 plot: [2,5] [=========>-------------------------------------------------------------------------------------] 11% est: 6s 
 plot: [2,6] [==========>------------------------------------------------------------------------------------] 11% est: 6s 
 plot: [2,7] [==========>------------------------------------------------------------------------------------] 12% est: 6s 
 plot: [2,8] [===========>-----------------------------------------------------------------------------------] 12% est: 6s 
 plot: [2,9] [===========>-----------------------------------------------------------------------------------] 13% est: 6s 
 plot: [2,10] [============>---------------------------------------------------------------------------------] 14% est: 6s 
 plot: [2,11] [============>---------------------------------------------------------------------------------] 14% est: 6s 
 plot: [2,12] [=============>--------------------------------------------------------------------------------] 15% est: 6s 
 plot: [2,13] [=============>--------------------------------------------------------------------------------] 15% est: 6s 
 plot: [3,1] [==============>--------------------------------------------------------------------------------] 16% est: 6s 
 plot: [3,2] [===============>-------------------------------------------------------------------------------] 17% est: 6s 
 plot: [3,3] [===============>-------------------------------------------------------------------------------] 17% est: 6s 
 plot: [3,4] [================>------------------------------------------------------------------------------] 18% est: 6s 
 plot: [3,5] [================>------------------------------------------------------------------------------] 18% est: 6s 
 plot: [3,6] [=================>-----------------------------------------------------------------------------] 19% est: 6s 
 plot: [3,7] [==================>----------------------------------------------------------------------------] 20% est: 6s 
 plot: [3,8] [==================>----------------------------------------------------------------------------] 20% est: 6s 
 plot: [3,9] [===================>---------------------------------------------------------------------------] 21% est: 6s 
 plot: [3,10] [===================>--------------------------------------------------------------------------] 21% est: 6s 
 plot: [3,11] [====================>-------------------------------------------------------------------------] 22% est: 6s 
 plot: [3,12] [====================>-------------------------------------------------------------------------] 22% est: 6s 
 plot: [3,13] [=====================>------------------------------------------------------------------------] 23% est: 6s 
 plot: [4,1] [=====================>-------------------------------------------------------------------------] 24% est: 6s 
 plot: [4,2] [======================>------------------------------------------------------------------------] 24% est: 6s 
 plot: [4,3] [=======================>-----------------------------------------------------------------------] 25% est: 6s 
 plot: [4,4] [=======================>-----------------------------------------------------------------------] 25% est: 6s 
 plot: [4,5] [========================>----------------------------------------------------------------------] 26% est: 6s 
 plot: [4,6] [========================>----------------------------------------------------------------------] 27% est: 6s 
 plot: [4,7] [=========================>---------------------------------------------------------------------] 27% est: 6s 
 plot: [4,8] [=========================>---------------------------------------------------------------------] 28% est: 6s 
 plot: [4,9] [==========================>--------------------------------------------------------------------] 28% est: 6s 
 plot: [4,10] [==========================>-------------------------------------------------------------------] 29% est: 5s 
 plot: [4,11] [===========================>------------------------------------------------------------------] 30% est: 5s 
 plot: [4,12] [===========================>------------------------------------------------------------------] 30% est: 5s 
 plot: [4,13] [============================>-----------------------------------------------------------------] 31% est: 5s 
 plot: [5,1] [=============================>-----------------------------------------------------------------] 31% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,2] [=============================>-----------------------------------------------------------------] 32% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,3] [==============================>----------------------------------------------------------------] 33% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,4] [==============================>----------------------------------------------------------------] 33% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [5,5] [===============================>---------------------------------------------------------------] 34% est: 5s 
 plot: [5,6] [================================>--------------------------------------------------------------] 34% est: 5s 
 plot: [5,7] [================================>--------------------------------------------------------------] 35% est: 5s 
 plot: [5,8] [=================================>-------------------------------------------------------------] 36% est: 5s 
 plot: [5,9] [=================================>-------------------------------------------------------------] 36% est: 5s 
 plot: [5,10] [=================================>------------------------------------------------------------] 37% est: 5s 
 plot: [5,11] [==================================>-----------------------------------------------------------] 37% est: 5s 
 plot: [5,12] [===================================>----------------------------------------------------------] 38% est: 5s 
 plot: [5,13] [===================================>----------------------------------------------------------] 38% est: 5s 
 plot: [6,1] [====================================>----------------------------------------------------------] 39% est: 5s 
 plot: [6,2] [=====================================>---------------------------------------------------------] 40% est: 5s 
 plot: [6,3] [=====================================>---------------------------------------------------------] 40% est: 5s 
 plot: [6,4] [======================================>--------------------------------------------------------] 41% est: 5s 
 plot: [6,5] [======================================>--------------------------------------------------------] 41% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [=======================================>-------------------------------------------------------] 42% est: 5s 
 plot: [6,7] [=======================================>-------------------------------------------------------] 43% est: 5s 
 plot: [6,8] [========================================>------------------------------------------------------] 43% est: 5s 
 plot: [6,9] [=========================================>-----------------------------------------------------] 44% est: 5s 
 plot: [6,10] [=========================================>----------------------------------------------------] 44% est: 5s 
 plot: [6,11] [=========================================>----------------------------------------------------] 45% est: 5s 
 plot: [6,12] [==========================================>---------------------------------------------------] 46% est: 5s 
 plot: [6,13] [==========================================>---------------------------------------------------] 46% est: 5s 
 plot: [7,1] [===========================================>---------------------------------------------------] 47% est: 5s 
 plot: [7,2] [============================================>--------------------------------------------------] 47% est: 5s 
 plot: [7,3] [=============================================>-------------------------------------------------] 48% est: 5s 
 plot: [7,4] [=============================================>-------------------------------------------------] 49% est: 4s 
 plot: [7,5] [==============================================>------------------------------------------------] 49% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,6] [==============================================>------------------------------------------------] 50% est: 4s 
 plot: [7,7] [===============================================>-----------------------------------------------] 50% est: 4s 
 plot: [7,8] [===============================================>-----------------------------------------------] 51% est: 4s 
 plot: [7,9] [================================================>----------------------------------------------] 51% est: 4s 
 plot: [7,10] [================================================>---------------------------------------------] 52% est: 4s 
 plot: [7,11] [=================================================>--------------------------------------------] 53% est: 4s 
 plot: [7,12] [=================================================>--------------------------------------------] 53% est: 4s 
 plot: [7,13] [==================================================>-------------------------------------------] 54% est: 4s 
 plot: [8,1] [===================================================>-------------------------------------------] 54% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,2] [===================================================>-------------------------------------------] 55% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,3] [====================================================>------------------------------------------] 56% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,4] [====================================================>------------------------------------------] 56% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,5] [=====================================================>-----------------------------------------] 57% est: 4s 
 plot: [8,6] [======================================================>----------------------------------------] 57% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,7] [======================================================>----------------------------------------] 58% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,8] [=======================================================>---------------------------------------] 59% est: 4s 
 plot: [8,9] [=======================================================>---------------------------------------] 59% est: 4s 
 plot: [8,10] [=======================================================>--------------------------------------] 60% est: 4s 
 plot: [8,11] [========================================================>-------------------------------------] 60% est: 4s 
 plot: [8,12] [========================================================>-------------------------------------] 61% est: 4s 
 plot: [8,13] [=========================================================>------------------------------------] 62% est: 4s 
 plot: [9,1] [==========================================================>------------------------------------] 62% est: 4s 
 plot: [9,2] [===========================================================>-----------------------------------] 63% est: 4s 
 plot: [9,3] [===========================================================>-----------------------------------] 63% est: 4s 
 plot: [9,4] [============================================================>----------------------------------] 64% est: 4s 
 plot: [9,5] [============================================================>----------------------------------] 64% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,6] [=============================================================>---------------------------------] 65% est: 3s 
 plot: [9,7] [=============================================================>---------------------------------] 66% est: 3s 
 plot: [9,8] [==============================================================>--------------------------------] 66% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,9] [===============================================================>-------------------------------] 67% est: 3s 
 plot: [9,10] [==============================================================>-------------------------------] 67% est: 3s 
 plot: [9,11] [===============================================================>------------------------------] 68% est: 3s 
 plot: [9,12] [================================================================>-----------------------------] 69% est: 3s 
 plot: [9,13] [================================================================>-----------------------------] 69% est: 3s 
 plot: [10,1] [=================================================================>----------------------------] 70% est: 3s 
 plot: [10,2] [=================================================================>----------------------------] 70% est: 3s 
 plot: [10,3] [==================================================================>---------------------------] 71% est: 3s 
 plot: [10,4] [==================================================================>---------------------------] 72% est: 3s 
 plot: [10,5] [===================================================================>--------------------------] 72% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,6] [===================================================================>--------------------------] 73% est: 3s 
 plot: [10,7] [====================================================================>-------------------------] 73% est: 3s 
 plot: [10,8] [=====================================================================>------------------------] 74% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,9] [=====================================================================>------------------------] 75% est: 3s 
 plot: [10,10] [=====================================================================>-----------------------] 75% est: 3s 
 plot: [10,11] [=====================================================================>-----------------------] 76% est: 2s 
 plot: [10,12] [======================================================================>----------------------] 76% est: 2s 
 plot: [10,13] [=======================================================================>---------------------] 77% est: 2s 
 plot: [11,1] [========================================================================>---------------------] 78% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,2] [========================================================================>---------------------] 78% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,3] [=========================================================================>--------------------] 79% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,4] [==========================================================================>-------------------] 79% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,5] [==========================================================================>-------------------] 80% est: 2s 
 plot: [11,6] [===========================================================================>------------------] 80% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,7] [===========================================================================>------------------] 81% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,8] [============================================================================>-----------------] 82% est: 2s 
 plot: [11,9] [============================================================================>-----------------] 82% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,10] [============================================================================>----------------] 83% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,11] [=============================================================================>---------------] 83% est: 2s 
 plot: [11,12] [=============================================================================>---------------] 84% est: 2s 
 plot: [11,13] [==============================================================================>--------------] 85% est: 2s 
 plot: [12,1] [===============================================================================>--------------] 85% est: 2s 
 plot: [12,2] [================================================================================>-------------] 86% est: 2s 
 plot: [12,3] [================================================================================>-------------] 86% est: 1s 
 plot: [12,4] [=================================================================================>------------] 87% est: 1s 
 plot: [12,5] [=================================================================================>------------] 88% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,6] [==================================================================================>-----------] 88% est: 1s 
 plot: [12,7] [==================================================================================>-----------] 89% est: 1s 
 plot: [12,8] [===================================================================================>----------] 89% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,9] [====================================================================================>---------] 90% est: 1s 
 plot: [12,10] [===================================================================================>---------] 91% est: 1s 
 plot: [12,11] [====================================================================================>--------] 91% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,12] [====================================================================================>--------] 92% est: 1s 
 plot: [12,13] [=====================================================================================>-------] 92% est: 1s 
 plot: [13,1] [======================================================================================>-------] 93% est: 1s 
 plot: [13,2] [=======================================================================================>------] 93% est: 1s 
 plot: [13,3] [=======================================================================================>------] 94% est: 1s 
 plot: [13,4] [========================================================================================>-----] 95% est: 1s 
 plot: [13,5] [=========================================================================================>----] 95% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,6] [=========================================================================================>----] 96% est: 0s 
 plot: [13,7] [==========================================================================================>---] 96% est: 0s 
 plot: [13,8] [==========================================================================================>---] 97% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,9] [===========================================================================================>--] 98% est: 0s 
 plot: [13,10] [==========================================================================================>--] 98% est: 0s 
 plot: [13,11] [===========================================================================================>-] 99% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,12] [===========================================================================================>-] 99% est: 0s 
 plot: [13,13] [=============================================================================================]100% est: 0s 
                                                                                                                           

mod_5 <- lm(price ~ sqft_living + lat + view, data = house_tidy)

summary(mod_5)

Call:
lm(formula = price ~ sqft_living + lat + view, data = house_tidy)

Residuals:
     Min       1Q   Median       3Q      Max 
-1596893  -115223   -14728    82111  4327282 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -3.438e+07  5.363e+05  -64.11   <2e-16 ***
sqft_living  2.502e+02  1.775e+00  140.93   <2e-16 ***
lat          7.228e+05  1.128e+04   64.08   <2e-16 ***
view         1.042e+05  2.125e+03   49.05   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 229400 on 21609 degrees of freedom
Multiple R-squared:  0.6095,    Adjusted R-squared:  0.6094 
F-statistic: 1.124e+04 on 3 and 21609 DF,  p-value: < 2.2e-16
par(mfrow = c(2, 2))
plot(mod_5)

mod_6 <- lm(price ~ sqft_living + lat + yr_built, data = house_tidy)

summary(mod_6)

Call:
lm(formula = price ~ sqft_living + lat + yr_built, data = house_tidy)

Residuals:
     Min       1Q   Median       3Q      Max 
-1645242  -120261   -14570    85543  4077885 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -2.770e+07  5.929e+05  -46.72   <2e-16 ***
sqft_living  2.936e+02  1.861e+00  157.79   <2e-16 ***
lat          6.551e+05  1.182e+04   55.40   <2e-16 ***
yr_built    -1.787e+03  5.875e+01  -30.42   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 236900 on 21609 degrees of freedom
Multiple R-squared:  0.5838,    Adjusted R-squared:  0.5838 
F-statistic: 1.011e+04 on 3 and 21609 DF,  p-value: < 2.2e-16
par(mfrow = c(2, 2))
plot(mod_6)

For the third predictor we will choose view over lat as it provide the higher r2 value.

Forth predictor

house_resid <- house_tidy %>% 
  add_residuals(mod_5) %>% 
  dplyr::select(-price)

coplot(resid ~ sqft_living | lat, 
       panel = function(x, y, ...){
         points(x, y)
         abline(lm(y ~ x), col = "blue")
       }, 
       data = house_resid, 
       columns = 6)


coplot(resid ~ lat | view, 
       panel = function(x, y, ...){
         points(x, y)
         abline(lm(y ~ x), col = "blue")
       }, 
       data = house_resid, 
       columns = 6)


coplot(resid ~ sqft_living | view, 
       panel = function(x, y, ...){
         points(x, y)
         abline(lm(y ~ x), col = "blue")
       }, 
       data = house_resid, 
       columns = 6)

LS0tCnRpdGxlOiAiUiBOb3RlYm9vayIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKYGBge3J9CmxpYnJhcnkodGlkeXZlcnNlKQpsaWJyYXJ5KG1vZGVscikKbGlicmFyeShHR2FsbHkpCmxpYnJhcnkoZ2dmb3J0aWZ5KQpsaWJyYXJ5KHJlbGFpbXBvKQpsaWJyYXJ5KGxtLmJldGEpCmBgYAoKIyBNVlAgMQoKYGBge3J9CiMgcmVhZCBpbiBkYXRhc2V0CmhvdXNlX2RhdGEgPC0gcmVhZF9jc3YoImRhdGEva2NfaG91c2VfZGF0YS5jc3YiKSAKCiMgY2xlYW4gZGF0YXNldApob3VzZV90aWR5IDwtIGhvdXNlX2RhdGEgJT4lIAogIGRwbHlyOjpzZWxlY3QoLWMoZGF0ZSwgaWQsIHNxZnRfbGl2aW5nMTUsIHNxZnRfbG90MTUsIHppcGNvZGUpKSAlPiUgCiAg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